/*
 * (#)MyUserDetailService.java 1.0 2010-6-23  
 */
/*
package com.huaxingbankas.core.base.spring.security;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.codelib.util.DateTimeUtils;
import com.codelib.util.DateUtilsExtend;
import com.ctc.wstx.util.DataUtil;
import com.hibernate.dao.UserDAO;
import com.hibernate.model.Role;
import com.hibernate.model.Users;



@Service("myUserDetailService")
public class MyUserDetailService implements UserDetailsService
{

	private UserDAO	userDAO;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException
	{
		Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
		if (StringUtils.isEmpty(username))
			throw new UsernameNotFoundException("username is null!");

		// �规��ㄦ�����洪�缃�
		List<Users> ulist = this.userDAO.findByUserName(username);
		if (ulist.size() > 0)
		{
			Users u = ulist.get(0);
			List<Role> rlist = (List<Role>) this.userDAO.findListBySQLQuery("SELECT a.roleName FROM dbo.role a INNER JOIN groupRole c ON a.roleId = c.roleId INNER JOIN dbo.groups b ON c.groupID = b.groupID inner join dbo.groupUser d on	b.groupId=d.groupID inner join dbo.users e on d.userid=e.userid WHERE (e.userName = '"
					+ username + "')",
					Role.class);
			for (Role role : rlist)
			{
				auths.add(new GrantedAuthorityImpl(role.getRoleName()));
			}
			// User(String username, String password, boolean enabled, boolean accountNonExpired,
			// boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities) {
			User user = new User(username, u.getPassWord(), "1".equals(u.getStatus())?true:false,  u.getExpired().compareTo((new Date()))>0?true:false, true, true, auths);
			return user;
		}
		else
		{
			throw new UsernameNotFoundException("username is not found!");
		}

	}

	@Resource
	public void setUserDAO(UserDAO userDAO)
	{
		this.userDAO = userDAO;
	}

}
*/